package com.lagou.service.impl;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Random;

@Service()
public class HelloServiceImpl implements HelloService {

    @Override
    public String sayHello(String name) {
        String host = RpcContext.getContext().getAttachment("host");
        String port = RpcContext.getContext().getAttachment("port");
        System.out.println("请求地址为：" + host + ":" + port);
        return "hello:" + name;
    }

    @Override
    public String methodA() {
        try {
            Thread.sleep((int) (Math.random() * 100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodA 被调用";
    }

    @Override
    public String methodB() {
        try {
            Thread.sleep((int) (Math.random() * 100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodB 被调用";
    }

    @Override
    public String methodC() {
        try {
            Thread.sleep((int) (Math.random() * 100));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "methodC 被调用";
    }
}
